/// <reference path="behavior_const.ts" />


namespace B{
    export class BehaviorTree{
        public static create(root:N_BehavBase):BehaviorTree{
            return new BehaviorTree(root);
        }

        private readonly _root:N_BehavBase;
        private runningNode:N_BehavBase;
        constructor(root:N_BehavBase){
            this._root = root;
        }

        public reset():void{
            if (this.runningNode == null) {
                let node = this.runningNode;
                this.runningNode = null;
                do{
                    node.reset();
                    node = node.parent;
                }while(node != null);
            }
        }
        

        public run():void{
            if (this.runningNode == null) {
                this._root.reset();
            }
        }
    }
}